package com.cp.util;

import com.google.common.collect.Lists;

import java.util.List;
import java.util.Objects;

/**
 * @author captain
 * @des:
 * @date 2021/9/21 15:48
 */
public class PageUtils {

    /**
     * des:
     * 手动分页
     *
     * @param list 分页集合
     * @param page 当前页数
     * @param size 每页条数
     * @return {@link List<T> }
     * @author captain
     * @date 2022/1/20 16:54
     */
    public static <T> List<T> manualPage(List<T> list, Integer page, Integer size) {
        if (Objects.isNull(list)) {
            return null;
        }
        List<List<T>> partition = Lists.partition(list, size);
        if (page > partition.size() - 1) {
            page = partition.size() - 1;
        }
        return partition.get(page);
    }
}
